package com.how2java.tmall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.how2java.tmall.mapper.UserMapper;
import com.how2java.tmall.pojo.User;
import com.how2java.tmall.service.UserService;

@Service
public class UserServiceImpl implements UserService{
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public void add(User c) {
		userMapper.insertSelective(c);
	}

	@Override
	public void delete(int id) {
		userMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void update(User c) {
		userMapper.updateByPrimaryKeySelective(c);
	}

	@Override
	public User get(int id) {
		return userMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<User> list() {
		return userMapper.getList();
	}

	@Override
	public boolean isExist(String name) {
		List<User> result= userMapper.getUserByName(name);
		if(!result.isEmpty()) {
			return true;
		}
		return false;
	}

	@Override
	public User get(String name, String password) {
		List<User> userList = userMapper.getUserByNameAndPassword(name,password);
		if(userList.isEmpty())
            return null;
        return userList.get(0);
	}

}
